﻿using System.Runtime.Serialization;
using System.Text;

namespace ToDoListReminder.Data
{
	/// <summary>
	/// Contains the task data.
	/// </summary>
	[DataContract]
	public class Task : BaseDataObject
	{
		#region Fields

		/// <summary>
		/// Holds the project name.
		/// </summary>
		private string projectName_;

		/// <summary>
		/// Holds the project name saved.
		/// </summary>
		private string projectNameSaved_;

		/// <summary>
		/// Holds the task name.
		/// </summary>
		private string taskName_;

		/// <summary>
		/// Holds the task name saved.
		/// </summary>
		private string taskNameSaved_;
		#endregion

		#region Properties

		/// <summary>
		/// Gets or sets the project name.
		/// </summary>
		[DataMember]
		public string ProjectName
		{
			get
			{
				return projectName_;
			}

			set
			{
				projectName_ = value;
				SetPropertyChanged("ProjectName");
			}
		}

		/// <summary>
		/// Gets or sets the task name.
		/// </summary>
		[DataMember]
		public string TaskName
		{
			get
			{
				return taskName_;
			}

			set
			{
				taskName_ = value;
				SetPropertyChanged("TaskName");
			}
		}
		#endregion

		#region Constructors

		/// <summary>
		/// Initializes a new instance of the Task class.
		/// </summary>
		/// <param name="projectName">The project name.</param>
		/// <param name="taskName">The task name.</param>
		public Task(string projectName, string taskName)
		{
			ProjectName = projectName;
			TaskName = taskName;
		}

		#endregion

		#region Overrides

		/// <summary>
		/// Gets the text representation of the instance.
		/// </summary>
		/// <returns>The text representation of the instance.</returns>
		public override string ToString()
		{
			var buffer = new StringBuilder("Task:");

			buffer.AppendFormat(" Project: \"{0}\"", ProjectName);
			buffer.AppendFormat(", TaskName: \"{0}\"", TaskName);

			return buffer.ToString();
		}
		#endregion

		/// <summary>
		/// Saves the data members.
		/// </summary>
		protected override void Save()
		{
			projectNameSaved_ = ProjectName;
			taskNameSaved_ = TaskName;
		}

		/// <summary>
		/// Restores the data members.
		/// </summary>
		protected override void Restore()
		{
			ProjectName = projectNameSaved_;
			TaskName = taskNameSaved_;
		}
	}
}
